package com.nineclock.auth.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * 配置令牌存储, 及令牌的类型(JWT)
 */
@Configuration
public class TokenConfig {

    //JWT令牌生成时的签名秘钥 ;
    @Value("${nineclock.auth.signKey}")
    private String SIGN_KEY;

    @Bean
    public TokenStore tokenStore(){
        return new JwtTokenStore(accessTokenConverter());
    }

    @Bean
    public JwtAccessTokenConverter accessTokenConverter(){
        JwtAccessTokenConverter accessTokenConverter = new JwtAccessTokenConverter() ;
        accessTokenConverter.setSigningKey(SIGN_KEY);
        return accessTokenConverter;
    }

}
